package cn.itcast.java.method;

import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * Author itcast
 * Date 2021/10/7 15:08
 * Desc TODO
 */
public class MethodDemo03 {
    public static void main(String[] args) {
        //定义重载方法，给不同的集合，计算集合的数据之和
        int[] arrs = {1,3,5,7,9};
        int add = add(arrs);
        System.out.println(add);
    }

    //int[]
    public static int add(int[] arr){
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }

    public static int add(List<Integer> lists){
        int sum = 0;
        for (Integer list : lists) {
            sum += list;
        }
        return sum;
    }

    public static int add(Set<Integer> sets){
        int sum = 0;
        for (Integer set : sets) {
            sum += set;
        }
        return sum;
    }
}
